//////////////////////////////////////////////////////////////////////////////////
// Company          :    Joinsilicon
// Engineer         :    Jinci.Bi
// Last Date        :    2024/05/30 10:20
// Module Name      :    LPDDR5 C driver
// Target Devices   : 
// Tool Versions    :    
// Dependencies     : 
// Revision 0.01    :    File Created
//////////////////////////////////////////////////////////////////////////////////
#include "mem_test.h"

//#define REG_BASE     (EN_DDR0_TEST ? 0x120000000 : 0x130000000)
#define REG_BASE0     0x120000000
#define REG_BASE1     0x130000000
// #define REG_BASE     0x120000000
//#define DDR_PHY_BASE (0x01000000 + REG_BASE)
#define DDR_PHY_BASE0 (0x01000000 + REG_BASE0)
#define DDR_PHY_BASE1 (0x01000000 + REG_BASE1)
void perh_reg_wr(unsigned int master, unsigned long long addr, unsigned int wdata, unsigned int strb);
unsigned int perh_reg_rd(unsigned int master, unsigned long long addr);
void pll_setting(unsigned int pll_fin, unsigned int target_freq, unsigned int bypass_mode);
void lpddr5_lf_initial(unsigned int pll_fin, unsigned int pll_fout, unsigned int pll_pass);
void lpddr5_hf_initial(unsigned int pll_fin, unsigned int pll_fout, unsigned int pll_pass, unsigned int phy_training);
void lpddr5_ctrl_static_reg_config(unsigned int phy_training, unsigned int target_freq);
void lpddr5_ctrl_static_reg_config_lf(unsigned int phy_training, unsigned int target_freq);
void lpddr5_ctrl_static_reg_config_hf(unsigned int phy_training, unsigned int target_freq);
void lpddr5_ctrl_initial_complete();
void lpddr5_mrw_config(unsigned int target_freq);
void lpddr5_ctrl_dynamic_reg_config();
void lpddr5_mrw(unsigned int mr_addr,unsigned int mr_value);
unsigned int lpddr5_mrr(unsigned int mr_addr);
void lpddr5_freq_wl_rl_trans(unsigned int target_freq);
void pll_direct(unsigned int pll_fin,unsigned int target_freq);
void lpddr5_phy_training(unsigned int phy_training, unsigned int target_freq,unsigned int phy_hw_cbt,unsigned int phy_wrlvl,unsigned int phy_rd,unsigned int phy_wr,unsigned int phy_prbs_rd,unsigned int phy_prbs_wr);
void samsung_common_setting_before_training(unsigned int target_freq);
void samsung_hwcal_cbt(unsigned int target_freq);
void samsung_wrlvl(unsigned int target_freq);
void samsung_rd(unsigned int target_freq);
void samsung_wr(unsigned int target_freq);
void samsung_prbs_rd(unsigned int target_freq);
void samsung_prbs_wr(unsigned int target_freq);
#define DELAY(delay_value) \
	do{ \
	volatile unsigned int delay_value_1 = delay_value;  \
	while (delay_value_1--); \
	}while(0) \
		;

